package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.monitor.entity.ErpHomepage;
import com.monitor.entity.ErpSystemParameters;
import com.monitor.entity.ErpSystemParametersChild;
import com.monitor.service.ErpHomepageService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 我的主页管理表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-26
 */
@RestController
@RequestMapping("/erpHomepage")
@Api(description="基础设置表")
public class ErpHomepageController {

    @Resource
    private ErpHomepageService homepageService;
    

    @RequestMapping("/inertOrUpdateHomepage")
    @ApiOperation("添加Or修改基础设置表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<ErpHomepage> inertOrUpdateHomepage(ErpHomepage homepage) {
        Result<ErpHomepage> result=new Result<ErpHomepage>();
        try{
            homepageService.insertOrUpdate(homepage);
            result.setCount(1);
            result.setData(homepage);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removeHomepage")
    @ApiOperation("删除基础设置表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "homepageId", value = "基础设置ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeHomepage(Integer homepageId) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(homepageService.deleteById(homepageId)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getHomepageById")
    @ApiOperation("根据基础设置表ID获取基础设置表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "homepageId", value = "基础设置表ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpHomepage> getHomepageById(Integer homepageId) {
        Result<ErpHomepage> result=new Result<ErpHomepage>();
        try{
            result.setCount(1);
            result.setData(homepageService.selectById(homepageId));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getChildByName")
    @ApiOperation("根据基础设置表name获取基础设置表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "childName", value = "基础设置表name", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<ErpHomepage> getChildByName(String childName) {
        Result<ErpHomepage> result=new Result<ErpHomepage>();
        try{
            result.setCount(1);
            result.setData(homepageService.selectOne(new EntityWrapper<ErpHomepage>().like("name",childName)));
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getHomepage")
    @ApiOperation("查询全部基础设置")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "parametersName", value = "系统参数名称", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<List<ErpHomepage>> getHomepage() {
        Result<List<ErpHomepage>> result=new Result<List<ErpHomepage>>();
        try{
            List<ErpHomepage> parametersList=homepageService.selectList(new EntityWrapper<ErpHomepage>());
            result.setCount(parametersList.size());
            result.setData(parametersList);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getHomepagePage")
    @ApiOperation("查询基础设置分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "parametersName", value = "系统参数名称", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Page<ErpHomepage>> getHomepagePage(@RequestParam(value = "page", defaultValue = "1") int page,
                                                        @RequestParam(value="limit",defaultValue="10") int limit) {
        Result<Page<ErpHomepage>> result=new Result<Page<ErpHomepage>>();
        try{
            Page<ErpHomepage> page1=new Page<ErpHomepage>(page,limit);
            Page<ErpHomepage> parametersList=homepageService.selectPage(page1,new EntityWrapper<ErpHomepage>());
            result.setCount(homepageService.selectCount(new EntityWrapper<ErpHomepage>()));
            result.setData(parametersList);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


}

